/**

 * slider class 
 */
function CustomSlider(className,width,height,timer){
	this.objectData = new Object();
	this.className 	= className;
	this.timer		= timer;
	this.width 		= width;
	this.height 		= height;
	this.init = init;
	this.getDom = getDom;
	this.getData = getData;
	this.showdowRender = showdowRender;
	this.showTitle = showTitle;
	this.switch_showpic = switch_showpic;
	this.setTimer = setTimer;
	this.slider = slider;
	this.updateDomData = updateDomData;
}

function init(){
	this.getDom();
	this.getData();
	this.showdowRender();
	this.showTitle();
	this.setTimer();
}

function getDom(){	
	var f = this.objectData = jQuery(this.className);
	f.image = f.find('.slider_image');
	f.shadow = f.find('.slider_shadow');
	f.title = f.find('.slider_title');
	f.description = f.find('.slider_description');
	f.navigation = f.find('.slider_navigation');
	f.t = this.timer || 6000;
}

function getData(){
	var  o = this.objectData;

	d = o.data = [];
	o.find('ul#slider_data').find('li').each(function( i ){
			d[i] = [];
			jQuery(this).find('p').each(function(){
				d[i].push(jQuery(this).html());
			});
	});
	
	o.size = this.objectData.data.length;
	o.now = 0;
	
	o.navigation.css({'display':'block',
		'opacity': 0.8,
		'position': 'absolute',
		'bottom': -100,
		'height': 15,
		'width': 200,
		'left':780,
		'zIndex': 50});					
	o.pointer = [];
	for (var i = 0;i<o.size;i++){
		var css_left = 10 + i* 30;
		o.pointer[i] = o.find('#pointer_'+i);
		o.pointer[i].css(
			{
			'display':'block',
			'background-image':'url(components/themes/main/images/button.png)',
			'background-repeat':'no-repeat',
			'position': 'absolute',
			'left': css_left,
			'bottom': '2px',
			'height': '10px',
			'width': '10px',
			'z-index': '50',
			'cursor':'pointer'
			}
		);
		o.pointer[i].bind('click',this,this.switch_showpic);
	}
	this.updateDomData(o);
}

function showdowRender(){
	var o = this.objectData;
 	h = 50;
	w = 430;
	o.shadow.bottom = -h - 20;
	o.description.bottom = -h;
	o.title.bottom = -h-20;
	o.shadow.css({'display':'block',
					'opacity': 0.5,
					'position': 'absolute',
					'bottom': -h - 20,
					'height': h + 50,
					'width': w,
					'zIndex': 20});
	o.shadow.parent().css({'position':'relative', 'overflow':'hidden'});													
	o.description.css({'position': 'absolute','bottom': -h+20, 'zIndex': 30});
	o.title.css({'position': 'absolute','bottom': -h, 'zIndex': 30});
}

function showTitle(){
	var o = this.objectData;
	o.navigation.animate({bottom: 0},'normal');
	o.shadow.animate({bottom: 15},'normal');
	o.description.animate({bottom: 8},'normal');
	o.title.animate({bottom: 50},'normal');
	
}

function switch_showpic(event){
	var o = event.handleObj.data.objectData;
	d = o.data;
	var clicked_id = event.target.id;
	o.now = parseInt(clicked_id.charAt(8));
	event.handleObj.data.updateDomData(o);
	event.handleObj.data.slider(o);	
}

function setTimer(){
	var o = this.objectData;
	d = o.data;
	o.timerPic = window.setInterval(function(){
			o.now = o.now + 1;
			if (o.now == o.size) {
					o.now = 0;
			}			
			this.updateDomData(o);
			this.slider(o);
	}, o.t);

}


function slider(o){
	o.image.hide();
	o.image.fadeIn(1000);
/*	o.image.animate({
	    width: ['toggle', 'swing'],
	    height: ['toggle', 'swing'],
	    opacity: 'toggle'
	  }, 5000, 'linear');
*/
}
function updateDomData(o){
	if (o == null) o = this.objectData;
	d = o.data;
	
			o.title.html( d[o.now][0] ).attr('href',d[o.now][1]);
			o.description.html(d[o.now][2]).attr('href',d[o.now][1]);
			o.image.parent().attr('href',d[o.now][1]);
			if(d[o.now][3] != undefined) o.image.attr('src', d[o.now][3] );		
			for (i = 0; i < o.size; i++){
				if (o.now == i) o.pointer[i].css('background-position','0 -10px');
				else o.pointer[i].css('background-position','0 0');
			}
}
